home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / snpd1292.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  2KB  |  94 lines

  1. /*
  2. ** FILES.C:  A program to determine the number of file handles
  3. **
  4. ** Released in to the Public Domian by Matthew Hunt @ 1:129/135, in the
  5. ** hopes that no "programmer" will be so lazy that he|she simple reads
  6. ** the CONFIG.SYS file ever again.
  7. **
  8. ** Any improvements and modifications are welcome, but I ask that all
  9. ** modified versions also be placed into the Public Domain.
  10. **
  11. ** Information on the List of Lists and SFT format was provided by
  12. ** PC Magazine November 26, 1991, and PC Interrupts by Ralf Brown
  13. ** and Jim Kyle.  FILES.C was originally written for Power C.
  14. **
  15. ** Modifcations for other compiler support by Bob Stout @ 1:106/2000.6
  16. */
  17.  
  18. #include <dos.h>
  19.  
  20. #ifdef __TURBOC__
  21.  #define FAR far
  22. #else
  23.  #define FAR _far
  24. #endif
  25.  
  26. #ifndef MK_FP
  27.  #define MK_FP(seg,offset) \
  28.         ((void FAR *)(((unsigned long)(seg)<<16) | (unsigned)(offset)))
  29. #endif
  30.  
  31. /*
  32. ** This is the format for a System File Table header.  SFT's are a linked
  33. ** list in which the header points to the next SFT, is followed by the
  34. ** number of FILES in this SFT, and ends with the FILES themselves, which
  35. ** are not important here.
  36. */
  37.  
  38. struct SFT_HEADER {
  39.       struct SFT_HEADER (FAR *next);
  40.       unsigned number;
  41. };
  42.  
  43. /*
  44. ** Walk the SFT linked list, counting file handles as we go
  45. */
  46.  
  47. int files(void)
  48. {
  49.       struct SFT_HEADER (FAR *sft);
  50.       unsigned int segment, offset;
  51.       int count=0;
  52.       union REGS regs;
  53.       struct SREGS sregs;
  54.  
  55.       /* Get ptr to List of Lists in ES:DX */
  56.  
  57.       regs.x.ax = 0x5200;
  58.       segread(&sregs);
  59.       intdosx(®s, ®s, &sregs);
  60.  
  61.       /* Get ssss:oooo to first SFT  */
  62.  
  63.       segment = *((unsigned FAR *)(MK_FP(sregs.es, regs.x.bx + 6)));
  64.       offset  = *((unsigned FAR *)(MK_FP(sregs.es, regs.x.bx + 4)));
  65.  
  66.       /* Point our structure to it.  */
  67.  
  68.       sft = MK_FP(segment, offset);
  69.  
  70.       do
  71.       {
  72.             count += sft->number;               /* Add the number of FILES */
  73.             sft = sft->next;                    /* Point to next one       */
  74.       } while(FP_OFF(sft->next) != 0x0FFFF);    /* Last one in the chain   */
  75.  
  76.       /* Add the FILES for the last entry */
  77.  
  78.       count += sft->number;
  79.       return count;
  80. }
  81.  
  82. #ifdef TEST
  83.  
  84. #include <stdio.h>
  85. #include <stdlib.h>
  86.  
  87. int main(void)
  88. {
  89.     printf("Number of FILES entries: %d", files());
  90.     return EXIT_SUCCESS;
  91. }
  92.  
  93. #endif /* TEST */
  94.